// PlacementDiaryEJB.java
package placementDiary;

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import javax.ejb.SessionContext;

import descriptor.PlacementDiaryDescriptor;

import servlets.Notification;
import servlets.WriteReadFile;
import student.Student;


/**
 * PlacementDiaryBean
 * 
 * @author Mamadou TOURE
 * 
 * The PlacementDiaryBean class implements all the methods that a remote client expect to find
 * when it calls the interface (PlacementDiary).
 * 
 * Note : 	-It extends the EntityBean class.
 */
public  abstract class PlacementDiaryBean implements EntityBean 
{
	// simple attributes
	/** 
	 * getId
	 * 
	 * The getId method returns a integer which indicates diary's identification number of a user.
	 * 
	 * @return		The diary's identification number of a user.
	 */
	public abstract int getId();
	
	/** 
	 * setId
	 * 
	 * The setId method sets the diary's identification number.
	 * 
	 * @param id		The new diary's identification number that we want to add.
	 */
	public abstract void setId(int id);
	
	/** 
	 * getContent
	 * 
	 * The getContent method returns a string which contains the diary.
	 * 
	 * @return		The diary's content.
	 */
	public abstract String getContent();
	
	/** 
	 * setContent
	 * 
	 * The setContent abstract method sets the content of the diary.
	 * 
	 * @param content		The new diary's content.
	 */
	public abstract void setContent(String content);
	
	//bean attributes
	//relation 1-1
	/** 
	 * getStudent
	 * 
	 * The getStudent abstract method returns an object of type Student which provides the student's details,
	 * (eg. userID,......).
	 * 
	 * @return		A student's object.
	 */
	public abstract Student getStudent();
	
	/** 
	 * setStudent
	 * 
	 * The setStudent abstract method sets an object of type Student.
	 * 
	 * @param student		A new user's object.
	 */
	public abstract void setStudent(Student student);
	
	/** 
	 * ejbCreate
	 * 
	 * The ejbCreate method defines the operations to follow to create an EJB.
	 * This method refers to the method create in the remote interface.
	 * 
	 * @param id				Diary's id.
	 * @param content			Diary's content.
	 * @param student			Diary's student owner.
	 * 
	 * @return 					Return's values is always null.
	 */
    public String ejbCreate(Student student) throws CreateException
    {
    	setContent(student.getLogin()+"_Diary.txt");
        return null;
    }

    public void ejbPostCreate(Student student) 
    {
    	WriteReadFile.write("",Notification.DiaryDir,getContent());
    	setStudent(student);
    } 
    
    /** 
	 * getDescriptor
	 * 
	 * The getDescriptor method provides a Java object instead of a bean object. Hence, the object is directly accessible from a servlet or a JSP. 
	 * 
	 * @param getId()					The ID of the diary
	 * @param getContent()				The diary's content
	 * @param getStudent()				The diary's student owner
	 * 
	 * @return 							A PlacementDiary Descriptor's object.
	 */
	public PlacementDiaryDescriptor getDescriptor()
	{
		return new PlacementDiaryDescriptor(getId(),getContent(),getStudent());
	}
    
    public void ejbActivate() throws EJBException, RemoteException {}
	public void ejbPassivate() throws EJBException, RemoteException {}
	public void ejbRemove() throws EJBException, RemoteException,RemoveException {}
	public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException {}
	public void ejbLoad() throws EJBException, RemoteException {}
	public void ejbStore() throws EJBException, RemoteException {}
	public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException {}
	public void unsetEntityContext() throws EJBException, RemoteException {}

}



